<template>
  <div id="app">
    <keep-alive>
      <!--<transition name="fade">-->
      <router-view v-if="$route.meta.keepAlive"/>
      <!--</transition>-->
    </keep-alive>
    <!--<transition name="fade">-->
    <router-view v-if="!$route.meta.keepAlive"></router-view>
    <!--</transition>-->
    <div>
      <mt-actionsheet
        :actions="actions"
        v-model="$store.state.dialog.sheetVisibleShow">
      </mt-actionsheet>
    </div>
  </div>
</template>

<script>
  import {getWeChatUrl} from './axios/api';
  import share from 'm-share';
  // import wx from 'weixin-js-sdk';
  import Vue from 'vue';
  import {getCityName,setCityName} from './assets/js/cache';
  import {Actionsheet} from 'mint-ui';
  // import { mapState } from 'vuex';
  Vue.component(Actionsheet.name, Actionsheet);
  export default {
    name: 'App',
    data() {
      return {
        details: {
          videoTitle: '分享测试',
          coverUrl: '',

        },
        weChatData: {},
        sheetVisible: this.$store.state.dialog.sheetVisibleShow,
        actions: [
          {
            name: '分享到朋友圈',
            method: () => {
              // this.testWechat();
              this.getWeChatData();
            }
          },
          {
            name: '返回首页',
            method: () => {
              this.$router.push({name: 'Index'})
            }
          }
        ]
      }
    },

    filters: {},
    computed: {
      getCircleOfFriendsTitle(){
        return this.$store.getters.getCircleOfFriendsTitle;
      },
      getCircleOfFriendsDesc(){
        return this.$store.getters.getCircleOfFriendsDesc;
      },
    },
    mounted() {

    },
    created(){
      if (getCityName() === undefined) {
        this.cityName = {CODE: '4601', region_name_c: '海口市', region_name_e: 'H'};
        setCityName(this.cityName);

      } else {
        this.cityName = getCityName();
      }
      // this.getWeChatData();
      // this.goWeChat();
    },
    methods: {
      // goWeChat(){
      //
      // },

      getWeChatData() {
        getWeChatUrl(location.href.split('#')[0]).then(res => {
          console.log(res);
          console.log(location.href.split('#')[0]);
          console.log(window.location.href);
          wx.config({
            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId: res.data.appId, // 必填，公众号的唯一标识
            timestamp: res.data.timestamp, // 必填，生成签名的时间戳
            nonceStr: res.data.nonceStr, // 必填，生成签名的随机串
            signature: res.data.signature, // 必填，签名
            jsApiList: [
              // 'onMenuShareAppMessage',
              'updateTimelineShareData'] // 此处填你所用到的方法
          });
          wx.ready(() => {
            let _this = this;
            wx.updateTimelineShareData({
              title: this.getCircleOfFriendsTitle, // 分享标题
              link: window.location.href, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
              desc:this.getCircleOfFriendsDesc,
              imgUrl: 'https://av.wuyoufang.com/assets/img/wechat.png',// 分享图标
              success: function () {
               //这里是回调函数

             }
            });

          });
          share.wxConfig({
            title: this.getCircleOfFriendsTitle,
            link: window.location.href,
            desc: this.getCircleOfFriendsDesc,
            imgUrl: 'https://av.wuyoufang.com/assets/img/wechat.png',
            wx: {
              appId: res.data.appId, // 必填，公众号的唯一标识
              timestamp: res.data.timestamp, // 必填，生成签名的时间戳
              nonceStr: res.data.nonceStr, // 必填，生成签名的随机串
              signature: res.data.signature // 必填，签名
            }
          });

          share.to('wxline', {
            title: this.getCircleOfFriendsTitle,
            link: window.location.href,
            desc: this.getCircleOfFriendsDesc,
            imgUrl: 'https://av.wuyoufang.com/assets/img/wechat.png',
            wx: {
              appId: res.data.appId, // 必填，公众号的唯一标识
              timestamp: res.data.timestamp, // 必填，生成签名的时间戳
              nonceStr: res.data.nonceStr, // 必填，生成签名的随机串
              signature: res.data.signature // 必填，签名
            }
          });
        })
      }

    }
  }




</script>

<style>
  #app {
    /*font-family: 'Avenir', Helvetica, Arial, sans-serif;*/
    /*-webkit-font-smoothing: antialiased;*/
    /*-moz-osx-font-smoothing: grayscale;*/
    /*text-align: center;*/
    /*color: #2c3e50;*/
    /*margin-top: 60px;*/
    /*font-size: 16px;*/
    /*padding-bottom: 50px;*/
  }

  .fade-enter-active, .fade-leave-active {
    opacity: 0;
    transition: opacity 1s;
  }
</style>
